$(document).ready(function() {
			$("#account").blur(checkacc);
			$("#password").blur(checklogpwd);
			$("#capcode").click(changecaptcha);
			$("#cgc").click(changecaptcha);
			$("#tips").hide();
			$("#loginBtn").click(submitLogin);
			$("#tempBtn").click(tempLogin);
			$("#registBtn").click(userReg);
			$("#captcha").keyup(submitbutton);//.blur(checkcaptcha);
			//$("#check").change(checklogaccept);
			changecaptcha();
		});
function checkLogin() {
	var cpfIpt = $("#captcha");
	if (cpfIpt.val().length==4) {
		if (checkacc() && checklogpwd()) {
			return true;
		} else {
			return false;
		}
	} else {
		tipShow("验证码不正确");
		changecaptcha();
		cpfIpt.focus();
		return false;
	}
}
function checkacc() {
	var accIpt = $("#account");
	var accstr = accIpt.val();
	if (!checknull(accstr) && !checkmin(accstr, 4) && !checkmax(accstr, 20)
			&& checkln(accstr)) {
		tipHide();
		return true;
	} else {
		tipShow("请输入正确的账号");
		return false;
	}
}
function checklogpwd() {
	var pwdIpt = $("#password");
	var pwdstr = pwdIpt.val();
	if (!checknull(pwdstr) && !checkmin(pwdstr, 6) && !checkmax(pwdstr, 32)) {
		tipHide();
		return true;
	} else {
		tipShow("请输入正确的密码");
		return false;
	}
}
function checklogaccept() {
//	var str = $("#check").attr("checked");
//	var str = document.getElementById("check").checked;
	if (document.getElementById("checkbox").checked) {
		tipHide();
		return true;
	} else {
		tipShow("您需要同意“用户使用议协”");
		return false;
	}
}
function submitLogin() {
	if (checkLogin()) {
		var accIpt = $("#account");
		var pwdIpt = $("#password");
		var cptIpt = $("#captcha");
		var subBtn = $("#loginBtn");
		var tipDiv = $("#tips");
		subBtn.val("登录中……");
		subBtn.attr("disabled", true);
		var accountstr = accIpt.val();
		var pwdstr = pwdIpt.val();
		var captchastr = cptIpt.val();
		$.ajax({
				type : "POST",
				url : "ChatUserPo",
				data : "m=userlogin&account=" + accountstr + "&pwd="
						+ pwdstr + "&captcha=" + captchastr,
				success : function (data) {
							if (data == "true") {
								window.location.href = "ChatUserPo?m=main";
							} else {
								subBtn.val("登录");
								subBtn.attr("disabled", false);
								tipShow(data);
								changecaptcha();
								pwdIpt.val("");
								cptIpt.val("");
							}
						},
				error : function () {
							subBtn.val("登录");
							subBtn.attr("disabled", false);
							tipShow("连接失败，请重试");
							changecaptcha();
							pwdIpt.val("");
							cptIpt.val("");
						}
			});
	}
}
function submitbutton(event) {
	//var evt = event!=null ? event : window.event;
	var k = event.keyCode || event.which;
	if (k == 13){//evt.keyCode == 13) {
		$("#loginBtn").click();
	}
}
function tempLogin() {
	if (checklogaccept()) {
		window.location.href = "ChatUserPo?m=login";
	}
}
function userReg() {
	window.location.href = "ChatUserPo?m=regpage";
}
function tipShow(str) {
	var tipDiv = $("#tips");
	tipDiv.html(str);
	tipDiv.show();
}
function tipHide() {
	var tipDiv = $("#tips");
	tipDiv.hide();
}

function setCookie(){
	var acookie=document.cookie.split("; ");
	for(var i=0;i<acookie.length;i++){
		var arr=acookie[i].split("=");
		if(arr[0] == "username"){
			document.getElementById("account").value = arr[1];
			break;
		}
			
	}	
}
